package Service;

import DAO.OpenDAO;
import Utils.Open;
import Utils.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class OpenService
{
    @Autowired
    private OpenDAO openDAO;

    public Boolean AddOpen(String UserId,String idcard,String account, String open_time) throws Exception
    {
        Boolean status = false;
        try {
            openDAO.Add_Open(UserId,idcard,account,open_time);
            status = true;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally {
            return status;
        }
    }
    public Open GetOpenById(String UserId)
    {
        Open open = null;
        try {
            open = null;
            open = openDAO.Get_OpenById(UserId);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        finally {
            return open;
        }
    }
    public ArrayList<Open> GetAllUnPassedOpen()
    {
        ArrayList<Open> openArrayList = null;
        try{
            openArrayList = openDAO.getAllUnPassedOpen();
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
        finally {
            return openArrayList;
        }
    }
    public boolean PassOpen(String UserId)
    {
        boolean status = false;
        try {
            openDAO.PassOpen(UserId);
            status = true;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally {
            return status;
        }
    }
}
